<?php

namespace lemon\repository;

use Yii;

/**
 * 补充lemonvine不能实现的方法
 * @author shaodd
 *
 */
class BaseCookie{
	/**
	 * 设置
	 * @param string $name
	 * @param unknown $value
	 */
	public static function setCookie24h($name, $value){
		$cookies = Yii::$app->response->cookies;
		$cookies->add(new \yii\web\Cookie([
			'name' => $name,
			'value' => $value,
			'expire'=>time()+86400,
		]));
	}
	
	/**
	 * 读取cookie
	 * @param string $name
	 * @return \yii\web\Cookie|string|boolean
	 */
	public static function get($name, $default=""){
		$cookies = Yii::$app->request->cookies;
		if(isset($cookies[$name])){
			return $cookies->get($name)->value;
		}
		return $default;
	}
	
}

